<template>
	<view>
		<view style="width: 750upx;height: 176upx;">
			<image src="../../static/shangmen/bj.png" style="width: 750upx;height: 176upx;position: absolute;"></image>
			<view style="display: flex;" @click="shangyibu">
				<view style="position: absolute;display: flex;margin-left: 20upx;line-height: 176upx;">
					<image src="../../static/shangmen/29.png" style="width: 38upx;height: 38upx;margin-top: 72upx;"></image>
				</view>
				<view style="width: 750upx;height: 176upx;text-align: center;font-size: 36upx;line-height: 176upx;position: absolute;z-index: 1;color: #fff;">选择汽车型号</view>
			</view>
		</view>
		<view style="height: 100upx;line-height: 100upx;margin-left: 20upx;font-size: 30upx;color: #333333;">汽车品牌：{{name}}</view>
		<view class="list">
			<view class="list_box" v-for="(item,index) in data" :key="index" @click="data_tap(index)">
				<image :src="item.is_show == 0?'../../static/shangmen/10.png':'../../static/shangmen/9.png'" class="list_box_img"></image>
				<view class="list_box_text">{{item.name}}</view>
			</view>
		</view>
		<view style="position: fixed;bottom: 20upx;width: 750upx;height: 100upx;background: #fff;">
			<view style="width: 690upx;height: 88upx;margin-top: 6upx;margin-left: 30upx;text-align: center;line-height: 88upx;font-size: 32upx;color: #FFFFFF;background: #1C346D;border-radius: 30upx;" @click="next_tap">下一步</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name:'',
				data:[],
				id:''
			}
		},
		onLoad(num) {
			this.id = num.id
			this.name = num.name
			this.car_car_api()
		},
		methods: {
			car_car_api(id) {
				var that = this
				that.$request(that.$Api.car_car_api, {
					access_token:uni.getStorageSync('access_token'),
					id:that.id
				},"POST").then(res => {
					for( let i=0;i<res.data.data.length;i++ ) {
						res.data.data[i]['is_show'] = 0
						res.data.data[i]['key'] = i
					}
					that.data = res.data.data
					console.log('res.data.data',res.data.data)
				})
			},
			shangyibu() {
				uni.navigateBack()
			},
			next_tap() {
				for( let i=0;i<this.data.length;i++ ) {
					if( this.data[i].is_show == 1 ) {
						var name = this.data[i].name
						console.log('name',name)
						this.car_save_api(name)
						return
					}
				}
			},
			car_save_api(name) {
				var that = this
				that.$request(that.$Api.car_save_api, {
					access_token:uni.getStorageSync('access_token'),
					name:name
				},"POST").then(res => {
					if(res.data.code == 0) {
						uni.navigateTo({
							url:'../conserve/conserve?name='+name
						})
					}
				})
			},
			data_tap(index) {
				for( let i=0;i<this.data.length;i++ ) {
					if( index == i ) {
						if( this.data[i].is_show == 0 ) {
							this.data[i].is_show = 1
						}else{
							this.data[i].is_show = 0
						}
					}else{
						this.data[i].is_show = 0
					}
				}
			},
		}
	}
</script>

<style lang="less">
	page{
		.list{
			.list_box{
				.list_box_text{
					font-size: 30upx;
					color: #333333;
					margin-left: 20upx;
				}
				.list_box_img{
					width: 36upx;
					height: 36upx;
				}
				padding: 30upx;
				display: flex;
			}
			width: 710upx;
			background: #fff;
			margin-left: 20upx;
			border-radius: 30upx;
			padding-bottom: 140upx;
		}
		background: #F4F4F4;
	}
</style>
